import request from "@/utils/request";

export default {
  // 分页查询待审核的申请
  needApproveList(searchModel) {
    return request({
      url: "/applications/needApproveList",
      method: "get",
      params: {
        pageNo: searchModel.pageNo,
        pageSize: searchModel.pageSize,
        status: searchModel.status,
        applicationNumber: searchModel.applicationNumber,
      },
    });
  },

  // 添加申请
  addApplication(data) {
    return request({
      url: "/applications/add",
      method: "post",
      data,
    });
  },

  // 删除申请
  deleteApplication(id) {
    return request({
      url: `/applications/delete/${id}`,
      method: "delete",
    });
  },

  // 更新申请
  updateApplication(data) {
    return request({
      url: "/applications/update",
      method: "put",
      data,
    });
  },

  // 审核订单
  reviewApplication(applicationsDto) {
    return request({
      url: "/applications/review",
      method: "post",
      data: applicationsDto,
    });
  },

  // 统一保存（新增 or 更新）
  saveApplication(data) {
    return data.id ? this.updateApplication(data) : this.addApplication(data);
  },

  // 更具id查询
  getApplicationById(id) {
    return request({
      url: `/applications/detail/${id}`,
      method: "get",
    });
  },

  // 查询调度信息
  getDispatchInfo(searchModel) {
    return request({
      url: "/applications/dispatchList",
      method: "get",
      params: {
        pageNo: searchModel.pageNo,
        pageSize: searchModel.pageSize,
        applicationNumber: searchModel.applicationNumber,
      },
    });
  },

  dispatch(dispatchDto) {
    return request({
      url: "/applications/dispatch",
      method: "post",
      data: dispatchDto,
    });
  },
};
